#include <bits/stdc++.h>

using namespace std;

const int MAXN = 8e4+10;
const int MAXQ = 1e5+10;

int c[MAXN],a[MAXN],st[MAXN],ed[MAXN],siz[MAXN],tot,b[MAXN],cnt,tt,ANS[MAXQ];
int BL,h[MAXN],n,m,top[MAXN],son[MAXN],dep[MAXN],ans,tim[MAXN],fa[MAXN];
bool used[MAXN];

struct edge{int v,nxt;}e[MAXN];

void link(int x,int y){e[++cnt] = (edge){y,h[x]};h[x] = cnt;}

struct query{
	int l,r,id,pos,lca;
	bool operator < (query&b) const{
		return pos == b.pos ? (pos & 1 ? r < b.r : r > b.r):pos < b.pos;
	}
}q[MAXQ];

void dfs(int x,int p){
	st[x] = ++tot;fa[x] = p;siz[x] = 1; dep[x] = dep[p]+1;
	a[x] = lower_bound(b+1,b+tt+1,a[x]) - b;
	c[st[x]] = x;
	for(int i = h[x];i;i = e[i].nxt){
		int y = e[i].v;
		if(y == p) continue;
		dfs(y,x);
		siz[x] += siz[y];
		if(siz[son[x]] < siz[y]) son[x] = y;
	}
	ed[x] = ++tot;c[ed[x]] = x;
}

void dfs1(int x,int anc){
	top[x] = anc;
	if(son[x]) dfs1(son[x],anc);
	for(int i = h[x];i;i = e[i].nxt){
		int y = e[i].v;
		if(y == fa[x] || y == son[x]) continue;
		dfs1(y,y);
	}
}

int lca(int x,int y){
	while(top[x] != top[y]){
		if(dep[top[x]] < dep[top[y]]) swap(x,y);
		x = fa[top[x]];
	}
	if(dep[x] >  dep[y]) swap(x,y);
	return x;
}

inline void cut(int x){ans -= !--tim[x];}

inline void add(int x){ans += !tim[x]++;}

inline void calc(int x){used[x] ? cut(a[x]):add(a[x]);used[x] ^= 1;}

int main (){
	scanf("%d %d",&n,&m);
	BL = sqrt(n<<1);
	for(int i = 1;i <= n;i++) scanf("%d",&a[i]),b[i] = a[i];
	for(int i = 1;i < n;i++){
		int x,y;scanf("%d %d",&x,&y);
		link(x,y);link(y,x);
	}
	sort(b+1,b+n+1);
	tt = unique(b+1,b+n+1) - b-1;
	dfs(1,0);
	dfs1(1,1);
	for(int i = 1;i <= m;i++) {
		scanf("%d %d",&q[i].l,&q[i].r);
		if(st[q[i].l] > st[q[i].r]) swap(q[i].l,q[i].r);
		q[i].id = i; 
		q[i].lca = lca(q[i].l,q[i].r);
		if(q[i].lca == q[i].l || q[i].lca == q[i].r) {
			q[i].lca = 0;
			q[i].l = st[q[i].l];
			q[i].r = st[q[i].r];
		}else{
			q[i].l = ed[q[i].l];
			q[i].r = st[q[i].r];
		}
		q[i].pos = (q[i].l-1)/BL+1;
	}
	sort(q+1,q+m+1);
	int l = 1,r = 0;
	for(int i = 1;i <= m;i++){
		while(l > q[i].l) calc(c[--l]);
		while(l < q[i].l) calc(c[l++]);
		while(r < q[i].r) calc(c[++r]);
		while(r > q[i].r) calc(c[r--]);
		if(q[i].lca) calc(q[i].lca);
		ANS[q[i].id] = ans;
		if(q[i].lca) calc(q[i].lca);
	}
	for(int i = 1;i <= m;i++)
		printf("%d\n",ANS[i]);
	return 0;
}
